baseFn.loading.call($('body'),'close')
$(function(){
    baseFn.loading.call($('body'),'close')
})
var _time = 60  
$('.verifycode').on('click',function(){
    var _text=$('.sign_user').find('input').val();
    if($(this).hasClass('active')){
        baseFn.popShow({
            txt:'当前不可获取'
        })
        return false
    }
    if(!(/^[1][3,4,5,7,8][0-9]{9}$/.test(_text))){
        baseFn.popShow({
            txt:'请输入正确的手机号'
        })
        return false;
    }else{
        if($(this).hasClass('active')){
            return false
        }else{
            $(this).addClass('active')
            time = setInterval(function(){
                $('.verifycode').text('还有'+_time+'秒')
                _time --
                if(_time == '0'){
                    _time = 60;
                    $('.verifycode').text('重新获取')
                    window.clearInterval(time)
                }
            },1000)
            $.get('http://wechat.xrtn.dmpp.net.cn/children/frontend/web/index.php?r=child/getcode',{user_phone:$.trim(_text)},function(res){
                baseFn.popShow({
                    txt:res.info
                })
            },'json')
        }    
    }
})
$('.loginbtn').on('click',function(){ 
   var _upDatas={
        user_phone:$('.sign_user').find('input').val(),
        code:$('.sign_pwd').find('input').val()
    }
    if(baseFn.getQueryString('user_name') != null){
        _upDatas.user_name = baseFn.getQueryString('user_name')
    }
    if(!(/^[1][3,4,5,7,8][0-9]{9}$/.test(_upDatas.user_phone))){
        baseFn.popShow({
            txt:'请输入正确的手机号'
        })
        return false;
    }else if(_upDatas.code == ''){
        baseFn.popShow({
            txt:'请输入验证码'
        })
        return false;
    }
    // console.log(_upDatas)
    if(baseFn.getQueryString('open_id') != null){
        storageControl.setStorageS({'openId':baseFn.getQueryString('open_id')})
        _upDatas.open_id = baseFn.getQueryString('open_id')
    }else if(storageControl.isExitStorageS('openId')){
        _upDatas.open_id = storageControl.getStorageS('openId')
    }
    $.get('http://wechat.xrtn.dmpp.net.cn/children/frontend/web/index.php?r=child/login',_upDatas,function(res){
        baseFn.popShow({
            txt:res.info,
            ok:function(){
                if(res.code == 1){
                    storageControl.setStorage({'tempUser':res.data.user_id +','+ Date.parse(new Date()),'userId':res.data.user_id})
                    window.location.replace('./index.html')
                }
            },
            timeable:true
        })
    },'json')
})
if(baseFn.getQueryString('open_id') != null){
    storageControl.setStorageS({'openId':baseFn.getQueryString('open_id')})
}
// console.log(storageControl.getStorage('userId'))
if(baseFn.getQueryString('open_id') != null){
    var _date = Date.parse(new Date())
    if(storageControl.isExitStorage('tempUser')){
        var _temp = storageControl.getStorage('tempUser').split(',')
        if(_temp[1]+ 3600*1000 >= _date){
            storageControl.setStorage({'userId':_temp[0],'tempUser':_temp[0]+','+_date})
            window.location.replace('./index.html')
        }
    }else if(baseFn.getQueryString('user_id') != null){
        storageControl.setStorage({'userId':baseFn.getQueryString('user_id')});
        window.location.replace('./index.html')
    }
    
}
